#include "KeypadManager.h"

/* PROTECTED REGION ID(Controller::KeypadManager_customCode) ENABLED START */

#include "fixedpoint.h"
#include "Button.h"

static int32_t desiredTemperature;

/* PROTECTED REGION END */

void KeypadManager_Runnable_initialize(void) {
	/* PROTECTED REGION ID(Controller::KeypadManager_RunnableInitializeFunc) ENABLED START */
	desiredTemperature = FIX_FROM_INT(25);
	KeypadManager_desiredTemperature_send(&desiredTemperature);
	/* PROTECTED REGION END */
}

void KeypadManager_Runnable(void) {
	/* PROTECTED REGION ID(Controller::KeypadManager_RunnableFunc) ENABLED START */
	KeypadEvent keypadEvent;

	KeypadManager_keypad_receive(&keypadEvent);
	if ((keypadEvent.keyCode & BUTTON_UP && desiredTemperature < FIX_FROM_INT(50)) || (keypadEvent.keyCode & BUTTON_DOWN && desiredTemperature > FIX_FROM_INT(
			10))) {
		desiredTemperature += keypadEvent.keyCode & BUTTON_UP ? FIX_FROM_INT(1) : -FIX_FROM_INT(1);
		KeypadManager_desiredTemperature_send(&desiredTemperature);
	}
	/* PROTECTED REGION END */
}
